import { http, fetchPost } from "@/utils/http";

// 获取商品分类
export function getGoodsCategoryAPI() {
  return http.request({
    url: "/rest/api/goods/category/onshelf",
    method: "GET"
  });
}

// 获取商品分类下的清单数
export function getCategoryCountAPI(categoryId) {
  return http.request({
    url: `/rest/api/goods/category/${categoryId}/count`,
    method: "GET"
  });
}

export function getGoodsPromptAPI(categoryId) {
  return http.request({
    url: `/rest/api/goods/category/${categoryId}`,
    method: "GET"
  });
}

// 获取智能产品推荐对话列表
export function getChatListAPI(data = { pageSize: 20, pageNumber: 1 }) {
  return http.request({
    url: "/rest/api/goods/chat/list",
    method: "POST",
    data
  });
}

// 获取对话历史记录
export function getChatHistoryAPI(chatId) {
  return http.request({
    url: `/rest/api/goods/chat/${chatId}`,
    method: "GET"
  });
}

// 创建新的智能产品推荐对话
export function createChat(data = { topic: "", categoryId: "", type: "" }) {
  data.type = "PRODUCT_RECOMMENDATION";
  return http.request({
    url: "/rest/api/goods/chat",
    method: "POST",
    data
  });
}

// 发送消息 -> Coze
export function sendCozeGoodPromptAPI(param, callBack) {
  const {
    user,
    conversationId,
    query,
    chatHistory = [],
    isSafeWareProduct
  } = param;
  console.log(
    "sendCozeGoodPromptAPI : ",
    user,
    conversationId,
    query,
    chatHistory
  );
  let data = {
    bot_id: isSafeWareProduct ? "7367629710522318898" : "7382860756469137471",
    conversation_id: conversationId,
    query,
    user,
    stream: true,
    chat_history: chatHistory
  };
  return fetchPost("/rest/api/coze/chat", data, callBack);
}

// 引导用户继续输入：基于用户的输入内容,获得让用户继续输入的提示语
export function sendGoodsPromptAPI(
  data = { chatId: "", info: "", categoryId: "" }
) {
  if (data.chatId.length === 0) {
    console.error("chatId is empty");
    return;
  }
  return http.request({
    url: `/rest/api/goods/chat/${data.chatId}/prompt`,
    method: "POST",
    data: { info: data.info, categoryId: data.categoryId }
  });
}

// 生成需求探寻的问题：基于用户的输入内容,推荐商品
export function getGoodsSeekPromptAPI(
  data = { chatId: "", info: "", categoryId: "" }
) {
  if (data.chatId.length === 0) {
    console.error("chatId is empty");
    return;
  }
  return http.request({
    url: `/rest/api/goods/chat/${data.chatId}/seek`,
    method: "POST",
    data: { info: data.info, categoryId: data.categoryId }
  });
}

// 商品推荐
export function sendGoodsRecommendAPI(
  data = { chatId: "", info: "", categoryId: "" }
) {
  if (data.chatId.length === 0) {
    console.error("chatId is empty");
    return;
  }
  return http.request({
    url: `/rest/api/goods/chat/${data.chatId}/recommend`,
    method: "POST",
    data: { info: data.info, categoryId: data.categoryId }
  });
}

// 生成报价单
export function sendMakeQuoteAPI(
  data = { chatId: "", info: "", categoryId: "", recommend: "" }
) {
  if (data.chatId.length === 0) {
    console.error("chatId is empty");
    return;
  }
  return http.request({
    url: `/rest/api/goods/chat/${data.chatId}/quote`,
    method: "POST",
    data: {
      info: data.info,
      categoryId: data.categoryId,
      recommend: data.recommend
    }
  });
}

// 普通问答
export function freeQAAPI(data = { chatId: "", info: "", categoryId: "" }) {
  if (data.chatId.length === 0) {
    console.error("chatId is empty");
    return;
  }
  return http.request({
    url: `/rest/api/goods/chat/${data.chatId}/answer`,
    method: "POST",
    data: { info: data.info, categoryId: data.categoryId }
  });
}

// 保存解析后的ai内容
export function saveAiContentAPI(
  chatId = "",
  msg = { message: "", questions: [] }
) {
  if (chatId.length === 0) {
    console.error("chatId is empty");
    return;
  }
  return http.request({
    url: `/rest/api/coze/chat/${chatId}/message`,
    method: "POST",
    data: { msg }
  });
}

// 更改智能产品推荐对话内容
export function changeGoodsChatInfo(
  data = { chatId: "", topic: null, pinned: null }
) {
  console.log("changeGoodsChatInfo : ", data);
  return http.request({
    url: `/rest/api/goods/chat/${data.chatId}`,
    method: "PATCH",
    data: { topic: data.topic, pinned: data.pinned }
  });
}

// 批量删除智能产品推荐对话内容
export function deleteGoodsChatInfoAPI(ids = []) {
  return http.request({
    url: "/rest/api/goods/chat",
    method: "DELETE",
    data: {
      ids
    }
  });
}

// 获取会议记录API
export function getMeetRecodsAPI(
  data = { pageNumber: 1, pageSize: 20, searchKey: "" }
) {
  return http.request({
    url: "/rest/api/conference/salesmate/records",
    method: "POST",
    data
  });
}

// 获取会议需求
export function getCustomerRequireMentAPI(conferenceId) {
  return http.request({
    url: `/rest/api/goods/chat/report/${conferenceId}/customer/requirement`,
    method: "GET"
  });
}
